Ext.onReady(function(){
	
	   var fromPanelInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'房产信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'房号',
			    	   name:'combinedName'
			    	   
				}, {
					 xtype:'displayfield',
			    	 fieldLabel:'房源状态',
			    	 name:'roomStatus'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'建筑面积',
			    	 name:'buildingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'套内面积',
			    	 name:'innerArea'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'分摊面积',
			    	 name:'sharingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'计价面积',
			    	 name:'buildingArea'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'拆前单价',
			    	 name:'unitPrice'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'拆前总价',
			    	 name:'totalPrice'
				} ]
			}]
		   
	   });
	   
	   
	   
	   
	   var custemInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'客户信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'客户姓名',
			    	   name:'customerName'
			    	   
				}, {
					 xtype:'displayfield',
			    	 fieldLabel:'证件号码',
			    	 name:'peDocumentNumber'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'证件类型',
			    	 name:'peDocumentType'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'联系电话',
			    	 name:'customerPhone'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'邮寄地址',
			    	 name:'peContactAddress'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'邮编',
			    	 name:'pePostcode'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'客户来源',
			    	 name:'customerOrigin'
				} ]
			}]
		   
	   });
	   
	   
	   var retainInfo = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'客户信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'有效日期',
			    	   id:'dateTime'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'保留原因',
			    	 name:'reason'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'经办人',
			    	 name:'agentCN'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'保留日期',
			    	 id:'retainDate'
				} ]
			}]
		   
	   });
	   
	   var retainRemark = Ext.create('Ext.form.FormPanel',{
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
	       title:'解除保留',
	       id:'jiechu',
	       hidden:true,
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'解除原因',
			    	   id:'remark'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'解除人',
			    	 name:'updateUser'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'解除日期',
			    	 id:'updateDate'
				} ]
			}]
		   
	   });
	   
		
	   var fromPanel =  Ext.create('Ext.form.FormPanel',{
	       renderTo:Ext.getBody(),
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
		   	defaultType : 'textfield',
			defaults : {
				anchor : '100%',
			},
			fieldDefaults : {
				flex : 1
			},
	       items:[fromPanelInfo,custemInfo,retainInfo,retainRemark],
	       dockedItems: [{
	            xtype: 'toolbar',
	            dock: 'bottom',
	            ui: 'footer',
	            layout: {
	                pack: 'center'
	            },
	            items: [{
	                minWidth: 80,
	                text: '撤销保留',
	                id:'check_button',
	                hidden:marketingRetainCancel,
	                handler:function(){
	                	 var window = createWindow();
//	                	 Ext.MessageBox.confirm("提示","是否确定撤销保留?",function(btn,txt){
//	                		 if(btn=="yes"){
//	                				Ext.Ajax.request({
//	                					url:jypath+'/marketing/retain/roomStatusRevoke',
//	                		    		params:{
//	                		    			"id":id
//	                		    		},
//	                		    		callback: function (options, success, response) {
//	                		    			 var obj = JSON.parse(response.responseText);
//	                		    			 if(obj.res=="1"){
//	                		    				 Ext.MessageBox.alert("系统提示","撤销成功");
//	                		    				 Ext.getCmp("check_button").setVisible(false);
//	                		    			 }
//	                		    		}
//	                				});
//	                		 }
//	                	 });
	                }
	            },{
	                minWidth: 80,
	                text: '返回',
	                handler:function(){
	                	if(returnUrl==''){
	                		location.href=jypath + "/marketing/room/index?menu="+menu;
	                	}else{
	                		location.href=jypath+returnUrl;
	                	}
	                }
	            }]
	        }
	        ]
	       
	       });
	   
	   
	   fromPanel.getForm().load({
			url:jypath+'/marketing/retain/responseResult',
			params:{'id':id},
			success:function(form, action){
				var obj = action.result.data;
				hideButton(obj);
				Ext.getCmp("retainDate").setValue(Ext.Date.format(new Date(obj.retainDate),'Y-m-d H:i:s'));
				var start = Ext.Date.format(new Date(obj.startValidity),'Y-m-d');
				var end = Ext.Date.format(new Date(obj.endValidity),'Y-m-d');
				Ext.getCmp("dateTime").setValue(start+"~"+end);
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
	   
	   function hideButton(obj){
		   //已解除保留，隐藏按钮
		   if(obj.retainType == 1){
			   //解除保留
			   var date = Ext.Date.format(new Date(obj.updateDate),'Y-m-d');
			   Ext.getCmp("updateDate").setValue(date);
			   Ext.getCmp("jiechu").show();
		   }
	   }
	   
	   /**
		 * 解除保留
		 * @param title
		 * @returns
		 */
		function createWindow(){
			return Ext.create('Ext.Window', {
		        title: '解除保留',
		        width: 450,
		        height: 200,
		        plain: true,
		        modal: true,
		        headerPosition: 'top',
		        items: [retainfromPanel]
		    }).show();
		} 
		
		var retainfromPanel = new Ext.form.FormPanel({
			region : 'north',
			frame : true,
			items:[
			       {
			    	   xtype:'textarea',
			    	   fieldLabel:'解除原因',
			    	   labelAlign:'right',
			    	   labelWidth:60,
			    	   width:420,
			    	   height:120,
				       id:'text'	   
			       }
			 ],
			 dockedItems: [{
		            xtype: 'toolbar',
		            dock: 'bottom',
		            ui: 'footer',
		            layout: {
		                pack: 'center'
		            },
		            items: [{
		                minWidth: 80,
		                text: '保存',
		                id:'save_button',
		                handler:function(){
		                	 Ext.MessageBox.confirm("提示","是否确定解除保留?",function(btn,txt){
		                		 if(btn=="yes"){
		                			 	var remark = Ext.getCmp("text").getValue();
		                			 	if(remark == ""){
		                			 		Ext.MessageBox.alert("系统提示","请填写解除原因");
		                			 		return false;
		                			 	}
		                			 	if(remark.length > 255){
		                			 		Ext.MessageBox.alert("系统提示","解除原因超出字数限制");
		                			 		return false;
		                			 	}
		                				Ext.Ajax.request({
		                					url:jypath+'/marketing/retain/roomStatusRevoke',
		                		    		params:{
		                		    			"id":id,
		                		    			"remark":remark
		                		    		},
		                		    		callback: function (options, success, response) {
		                		    			 var obj = JSON.parse(response.responseText);
		                		    			 if(obj.res=="1"){
		                		    				 Ext.MessageBox.alert("系统提示","解除成功");
		                		    				 //Ext.getCmp("check_button").setVisible(false);
		                		    				 location.reload(true);
		                		    			 }
		                		    		}
		                				});
		                		 }
		                	 });
		                }
		            }]
		      }]
		});
		
});